import 'package:flutter/material.dart';
import 'package:flutter_axrjc/routes.dart';
import 'package:flutter_axrjc/widget/common_widget.dart';
import 'package:get/get.dart';
import 'package:pull_to_refresh/pull_to_refresh.dart';

import 'logic.dart';

class KnowledgeForEyePage extends StatelessWidget {
  const KnowledgeForEyePage({Key? key}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    final logic = Get.find<KnowledgeForEyeLogic>();
    final state = Get.find<KnowledgeForEyeLogic>().state;
    return Scaffold(
      backgroundColor: const Color(0xffF3F6F9),
      appBar: AppBar(
        backgroundColor: Colors.white,
        foregroundColor: Colors.black,
        titleSpacing: -10,
        elevation: 0,
        centerTitle: true,
        title: const Text(
          "护眼知识",
          style: TextStyle(fontSize: 15, fontWeight: FontWeight.bold),
        ),
      ),
      body: SmartRefresher(
        header: reFreshHeader(),
        footer: loadFooter(),
        enablePullUp: true,
        enablePullDown: true,
        onLoading: () {
          logic.getPage(isRefresh: false);
        },
        onRefresh: () {
          logic.getPage(isRefresh: true);
        },
        controller: logic.refreshController,
        child: Obx(() {
          return ListView.builder(
            shrinkWrap: true,
            physics: const NeverScrollableScrollPhysics(),
            itemCount: state.list.length,
            itemBuilder: (BuildContext context, int index) {
              var bean = state.list[index];
              return GestureDetector(
                onTap: () {
                  Get.toNamed(MainRoutes.knowledgeDetail, arguments: bean);
                },
                child: Padding(
                  padding: const EdgeInsets.all(8.0),
                  child: Container(
                    padding: const EdgeInsets.all(15),
                    decoration: const BoxDecoration(color: Colors.white),
                    child: Row(
                      crossAxisAlignment: CrossAxisAlignment.start,
                      children: [
                        Expanded(
                            child: Column(
                          crossAxisAlignment: CrossAxisAlignment.start,
                          children: [
                            Text(
                              "${bean.articleTitle}",
                              style: const TextStyle(
                                  fontSize: 14, color: Color(0xff3d3d3d)),
                            ),
                            const SizedBox(
                              height: 5,
                            ),
                            Text(
                              "${bean.articleContent}",
                              maxLines: 2,
                              style: const TextStyle(
                                  fontSize: 12, color: Color(0xff3d3d3d)),
                              overflow: TextOverflow.ellipsis,
                            ),
                          ],
                        )),
                        bean.articelHomePic == null
                            ? Container()
                            : Row(
                                children: [
                                  const SizedBox(
                                    width: 10,
                                  ),
                                  ClipRRect(
                                    borderRadius: BorderRadius.circular(5),
                                    child: SizedBox(
                                      width: 80,
                                      height: 80,
                                      child: Image.network(
                                        "${bean.articelHomePic}",
                                        fit: BoxFit.cover,
                                      ),
                                    ),
                                  )
                                ],
                              )
                      ],
                    ),
                  ),
                ),
              );
            },
          );
        }),
      ),
    );
  }
}
